package relu.R.birds;
import java.util.*;
import relu.R.weeds.*;

public class BirdSpecies {
	public final double homeRange;
	public final String name;
	public final double dailyRation;
	public final double hedgeBreedingRequirement;
	public final double meanClutchSize;
	public final double varClutchSize;
	public final double rsurv;
	public final ArrayList<WeedSpecies> diet=new ArrayList<WeedSpecies>();
	private final Map<WeedSpecies,Double> foodFromWeedSpecies=new HashMap<WeedSpecies,Double>();
	
	// Weight in this case should represent the food in kj per seed gained from this species
	public void addToDiet(WeedSpecies sp,double weight){
		diet.add(sp);
		foodFromWeedSpecies.put(sp,weight);
	}
	
	// Amount is seeds per hectare so this function converts from seeds/hectare to kj gained per hectare
	public double foodFromWeedSpecies(double amount,WeedSpecies sp){
		if ( !foodFromWeedSpecies.containsKey(sp)){
		//	throw new Error("The weed species "+sp+" was not specified in the diet of this bird species");
			return 0; // No food if species not defined in diet;
		}
		return amount*foodFromWeedSpecies.get(sp);
	}
	
	// From Phil S. Code ... Nagy 1987 Field Metabolic Rate 
	public static double NagyFormula(double weight){
		/*logMass:=log10(Mass);
		temp1:=10; temp2:=1.037+0.64*logMass;
		DR:=power(temp1,temp2);*/
		double lfmr=1.037+0.640*Math.log10(weight);
		
		return Math.pow(lfmr, 10);
	}
	
	public BirdSpecies(double hr,String name_,double weight,double hedgeReq,double mc,double vc,double rs){
		homeRange=hr;
		name=name_;
		rsurv=rs;
		dailyRation=1.5*2*BirdSpecies.NagyFormula(weight);
		// Times 1.5 because of inefficient use of energy
		// Times 2 because 1 bird = 1 BP
		hedgeBreedingRequirement=hedgeReq;
		meanClutchSize=mc;
		varClutchSize=vc;
	}

	public boolean equals(Object other){
		if ( this == other ){ return true;};
		if ( other instanceof BirdSpecies){
			BirdSpecies oth=(BirdSpecies)other;
			if ( oth.homeRange==homeRange&& oth.name==name && oth.dailyRation==dailyRation){
				return true;
			} 
		}
		return false;
	}
	public int hashCode(){
		int hash=7;
		hash=31*hash+(int)homeRange;
		hash=31*hash+(int)dailyRation;
		hash=31*hash+name.hashCode();
		return hash;
	}
}
